package com.icomvn.game.pikachu.music;

import android.app.Activity;
import android.media.MediaPlayer;

import com.icomvn.game.pikachu.R;

public class PlayMusic implements Runnable {
	Activity activity;
	public boolean playMusic = true, playSound = true;
	public MediaPlayer music, sound;
	Thread mthread;

	public PlayMusic(Activity activity) {
		this.activity = activity;
		sound = MediaPlayer.create(activity, R.raw.andiem);
	}

	public void checkTrue() {
		if (playSound) {
			sound.release();
			sound = MediaPlayer.create(activity, R.raw.andiem);
			sound.start();
		}
	}

	public void playMiss() {
		if (playSound) {
			sound.release();
			sound = MediaPlayer.create(activity, R.raw.saimiss);
			sound.setVolume(150, 150);
			sound.start();
		}
	}

	public void win() {
		sound.release();
		if (playSound) {
			sound = MediaPlayer.create(activity, R.raw.thangquaban);
			sound.start();
		}
	}

	public void timeOver() {
		if (playSound) {
			sound.release();
			sound = MediaPlayer.create(activity, R.raw.thuahetthoigian);
			sound.start();
		}
	}

	public void musicBg() {
		if (playMusic) {
			music = MediaPlayer.create(activity, R.raw.nhacnen);
			music.setLooping(true);
			music.start();
		}
	}

	public void chose() {
		if (playSound) {
			sound.release();
			sound = MediaPlayer.create(activity, R.raw.luachon);
			sound.start();
		}
	}

	public void startMusic() {
		mthread = new Thread(this);
		mthread.start();
	}

	public void run() {
		musicBg();
	}

	public void stopMusic() {
		if (playMusic) {
			music.stop();
			music.release();
		}
	}

	public void stopSound() {
		if (sound != null && sound.isPlaying()) {
			sound.stop();
		}
	}

}